//
//  CustomCell.m
//  MKWebImage
//
//  Created by lily on 17/1/2.
//  Copyright © 2017年 lily. All rights reserved.
//

#import "CustomCell.h"
#import "UIImageView+Cache.h"

@interface CustomCell ()

@property (nonatomic, strong) UIImageView *igv;
@property (nonatomic, strong) UILabel *lbTitle;
@property (nonatomic, strong) UILabel *lbSummar;

@end

@implementation CustomCell

- (void)setModel:(NSDictionary *)dict {
    //self.lbTitle.text = dict[@"name"];
    //self.lbSummar.text = dict[@"description"];
//    [self.igv mk_setImageWithUrl:dict[@"picture"] placeHolder:[UIImage imageNamed:@"default"] complete:^(UIImage *image, BOOL cache) {
//    }];
    self.lbTitle.text = dict[@"title"];
    
    //NSString *idstr = dict[@"id"];
    
//    NSNumber转NSString
//    NSString *A = [[NSString alloc] init];
//    NSNumber *B = [NSNumber numberWithInt:123456];
//    A = [NSString stringWithFormat:@"%@",B];
//    链接：https://www.jianshu.com/p/061f13f90f07
    
    NSNumber *idstr = dict[@"detail"];
    NSString *disid = [NSString stringWithFormat:@"%ld",(long)idstr.integerValue];
    //NSLog(@"id = %d",idstr.integerValue);
    self.lbSummar.text = disid;
    
    [self.igv mk_setImageWithUrl:dict[@"img"] placeHolder:[UIImage imageNamed:@"default"] complete:^(UIImage *image, BOOL cache) {
    }];
}

- (UIImageView *)igv {
    if (!_igv) {
        _igv = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 120, 68)];
        _igv.contentMode = UIViewContentModeScaleAspectFill;
        _igv.clipsToBounds = YES;
        [self.contentView addSubview:_igv];
    }
    return _igv;
}

- (UILabel *)lbTitle {
    if (!_lbTitle) {
        _lbTitle = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.igv.frame) + 15, 5, [UIScreen mainScreen].bounds.size.width - CGRectGetMaxX(self.igv.frame) + 30 , 40)];
        _lbTitle.numberOfLines = 2;
        _lbTitle.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_lbTitle];
    }
    return _lbTitle;
}

- (UILabel *)lbSummar {
    if (!_lbSummar) {
        _lbSummar = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.igv.frame) + 15, CGRectGetMaxY(self.lbTitle.frame), [UIScreen mainScreen].bounds.size.width - CGRectGetMaxX(self.igv.frame) + 30 , 33)];
        _lbSummar.numberOfLines = 2;
        _lbSummar.font = [UIFont systemFontOfSize:13];
        _lbSummar.textColor = [UIColor lightGrayColor];
        [self.contentView addSubview:_lbSummar];
    }
    return _lbSummar;
}
@end
